{% extends 'base/base.html' %}

{% block title %}注册 - 环保监测数据管理系统{% endblock %}

{% block extra_css %}
<style>
    .register-container {
        max-width: 500px;
        margin: 50px auto;
    }
    .register-header {
        text-align: center;
        margin-bottom: 30px;
    }
    .register-header h1 {
        color: var(--primary-color);
        font-weight: 600;
    }
    .register-form {
        background-color: #fff;
        padding: 30px;
        border-radius: 5px;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    }
    .register-footer {
        text-align: center;
        margin-top: 20px;
    }
    .btn-register {
        width: 100%;
        padding: 10px;
        font-weight: 600;
    }
    .verification-code-container {
        display: flex;
        align-items: center;
    }
    .verification-code-img {
        margin-left: 10px;
        cursor: pointer;
        height: 40px;
        border: 1px solid #ced4da;
        border-radius: 0.25rem;
    }
</style>
{% endblock %}

{% block main_content %}
<div class="register-container">
    <div class="register-header">
        <h1>环保监测数据管理系统</h1>
        <p>创建新账号</p>
    </div>
    <div class="register-form">
        <form method="post">
            {% csrf_token %}
            <div class="mb-3">
                <label for="{{ form.username.id_for_label }}" class="form-label">{{ form.username.label }}</label>
                {{ form.username }}
                {% if form.username.errors %}
                <div class="invalid-feedback d-block">
                    {{ form.username.errors.0 }}
                </div>
                {% endif %}
            </div>
            <div class="mb-3">
                <label for="{{ form.email.id_for_label }}" class="form-label">{{ form.email.label }}</label>
                {{ form.email }}
                {% if form.email.errors %}
                <div class="invalid-feedback d-block">
                    {{ form.email.errors.0 }}
                </div>
                {% endif %}
            </div>
            <div class="mb-3">
                <label for="{{ form.password1.id_for_label }}" class="form-label">{{ form.password1.label }}</label>
                {{ form.password1 }}
                {% if form.password1.errors %}
                <div class="invalid-feedback d-block">
                    {{ form.password1.errors.0 }}
                </div>
                {% endif %}
            </div>
            <div class="mb-3">
                <label for="{{ form.password2.id_for_label }}" class="form-label">{{ form.password2.label }}</label>
                {{ form.password2 }}
                {% if form.password2.errors %}
                <div class="invalid-feedback d-block">
                    {{ form.password2.errors.0 }}
                </div>
                {% endif %}
            </div>
            <div class="mb-3">
                <label for="{{ form.verification_code.id_for_label }}" class="form-label">{{ form.verification_code.label }}</label>
                <div class="verification-code-container">
                    {{ form.verification_code }}
                    <img id="verification-code-img" src="{% url 'accounts:verification_code' %}" alt="验证码" class="verification-code-img">
                </div>
                {% if form.verification_code.errors %}
                <div class="invalid-feedback d-block">
                    {{ form.verification_code.errors.0 }}
                </div>
                {% endif %}
            </div>
            {% if form.non_field_errors %}
            <div class="alert alert-danger">
                {% for error in form.non_field_errors %}
                {{ error }}
                {% endfor %}
            </div>
            {% endif %}
            <div class="d-grid gap-2 mt-4">
                <button type="submit" class="btn btn-primary btn-register">注册</button>
            </div>
        </form>
    </div>
    <div class="register-footer">
        <p>已有账号? <a href="{% url 'accounts:login' %}">立即登录</a></p>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    // 点击验证码图片刷新
    document.getElementById('verification-code-img').addEventListener('click', function() {
        this.src = "{% url 'accounts:verification_code' %}?" + new Date().getTime();
    });
</script>
{% endblock %} 